CREATE TABLE [dbo].[Site](
	[ID_Sit] [int] IDENTITY(0,1) NOT NULL,
	[CODSITE] [varchar](max) NULL,
	[NOMSITE] [varchar](max) NULL,
	[LATDD_SIT] [varchar](max) NULL,
	[LatDDS_Sit] [varchar](max) NULL,
	[LatDDN_Sit] [varchar](max) NULL,
	[LATS_SIT] [varchar](max) NULL,
	[LATN_SIT] [varchar](max) NULL,
	[LATM_SIT] [varchar](max) NULL,
	[LONDD_SIT] [varchar](max) NULL,
	[LonDDS_Sit] [varchar](max) NULL,
	[LonDDW_Sit] [varchar](max) NULL,
	[LONE_SIT] [varchar](max) NULL,
	[LONW_SIT] [varchar](max) NULL,
	[LONM_SIT] [varchar](max) NULL,
	[ALTI_SIT] [varchar](10) NULL,
	[ALTS_SIT] [varchar](10) NULL,
	[ALTM_SIT] [varchar](max) NULL,
	[PERIM_SIT] [varchar](90) NULL,
	[SRFCE_SIT] [numeric](5, 0) NULL,
	[DELIM_SIT] [varchar](max) NULL,
	[LOCTXT_SIT] [varchar](max) NULL,
	[NOTES_SIT] [varchar](max) NULL,
	
 CONSTRAINT [PK_SITE] PRIMARY KEY CLUSTERED 
(
	[ID_Sit] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[SiteTyp]    Script Date: 10/18/2012 12:45:19 ******/

CREATE TABLE [dbo].[SiteTyp](
	[Id_SiteTyp] [int] IDENTITY(0,1) NOT NULL,
	[CODE_SiteTyp] [char](5) NULL,
	[NOM_SiteTyp] [char](50) NULL,
	[DESC_SiteTyp] [varchar](90) NULL,
 CONSTRAINT [Id_SiteTyp] PRIMARY KEY CLUSTERED 
(
	[Id_SiteTyp] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[SITES_APP]    Script Date: 10/18/2012 12:45:19 ******/

CREATE TABLE [dbo].[SiteAppelation](
	[SITE_APPEL_ID] [int] IDENTITY(1,1) NOT NULL,
	[ID_Sit] [int] NOT NULL,
	[APPELATION] [varchar](100) NOT NULL,
	[NOTE] [varchar](max) NULL,
 CONSTRAINT [PK_SiteAppelation_1] PRIMARY KEY CLUSTERED 
(
	[SITE_APPEL_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[SiteAppelation]  WITH CHECK ADD  CONSTRAINT [FK_SiteAppelation_Site1] FOREIGN KEY([ID_Sit])
REFERENCES [dbo].[Site] ([ID_Sit])
GO

ALTER TABLE [dbo].[SiteAppelation] CHECK CONSTRAINT [FK_SiteAppelation_Site1]
GO



CREATE TABLE [dbo].[Users](
	[UserID] [int] IDENTITY(1,1) NOT NULL,
	[FullName] [nvarchar](50) NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[Password] [varchar](32) NOT NULL,
	[PermissionID] [tinyint] NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[UserID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[Permissions](
	[PermissionID] [tinyint] IDENTITY(1,1) NOT NULL,
	[Description] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Permission] PRIMARY KEY CLUSTERED 
(
	[PermissionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[Actions](
	[actionID] [int] IDENTITY(1,1) NOT NULL,
	[permissionID] [tinyint] NOT NULL,
	[action_desc] [text] NULL,
	[action_name] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[Actions]  WITH CHECK ADD  CONSTRAINT [FK_Actions_Permissions] FOREIGN KEY([permissionID])
REFERENCES [dbo].[Permissions] ([PermissionID])
GO

ALTER TABLE [dbo].[Actions] CHECK CONSTRAINT [FK_Actions_Permissions]
GO

CREATE TABLE [dbo].[LayersSiteConfig](
	[layerName] [varchar](100) NOT NULL,
	[layerLabel] [varchar](100) NOT NULL,
	[layerActif] [bit] NOT NULL,
	[layerForm] [varchar](100) NULL,
	[layerTable] [varchar](100) NULL
) ON [PRIMARY]
SET ANSI_PADDING ON
/****** Object:  Index [PK_LayersSiteConfig2]    Script Date: 12/05/2012 16:25:06 ******/
ALTER TABLE [dbo].[LayersSiteConfig] ADD  CONSTRAINT [PK_LayersSiteConfig] PRIMARY KEY CLUSTERED 
(
	[layerName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO


INSERT INTO [dbo].[Permissions]
           ([Description])
     VALUES
           ('Gestionnaire d application')


INSERT INTO [dbo].[Permissions]
           ([Description])
     VALUES
           ('Utilisateur')


INSERT INTO [dbo].[Permissions]
           ([Description])
     VALUES
           ('GisUser')


INSERT INTO [dbo].[Permissions]
           ([Description])
     VALUES
           ('Observateur')


INSERT INTO [dbo].[Users]
           ([FullName]
           ,[UserName]
           ,[Password]
           ,[PermissionID])
     VALUES
           ('Manager'
           ,'Manager'
           ,'AE94BE3CD532CE4A025884819EB08C98'
           ,1)

	
	 INSERT INTO [dbo].[Users]
           ([FullName]
           ,[UserName]
           ,[Password]
           ,[PermissionID])
     VALUES
           ('user'
           ,'user'
           ,'EE11CBB19052E40B07AAC0CA060C23EE'
		   ,2)
         

INSERT INTO [SILM-1.0].[dbo].[Actions]
           ([permissionID]
           ,[action_desc]
           ,[action_name])
     VALUES
           (1
           ,'Ajouter un site'
           ,'add_site_action')
GO

INSERT INTO [SILM-1.0].[dbo].[Actions]
           ([permissionID]
           ,[action_desc]
           ,[action_name])
     VALUES
           (1
           ,'Configuration'
           ,'config_action')
GO